package com.example.myapplication.presenter;


import android.app.Activity;
import android.app.Dialog;
import android.content.Context;

import com.example.myapplication.api.HostType;
import com.example.myapplication.base.RxPresenter;
import com.example.myapplication.model.bean.PhotoGirl;
import com.example.myapplication.model.https.RetrofitHelpers;
import com.example.myapplication.model.rx.RxSubscriber;
import com.example.myapplication.presenter.contract.GrilContract;
import com.example.myapplication.ui.wight.LoadingDialog;
import com.example.myapplication.utils.LogUtils;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/*      *
 * Created by yin97 on 2017/4/4.
 */

public class GrilPresenter extends RxPresenter<GrilContract.View> implements GrilContract.Presenter {
    Context mContext;

    public GrilPresenter(Context context) {
        this.mContext=context;
    }

    @Override
    public void requestSplashData(int size, int paget) {
        Dialog dialog= LoadingDialog.showDialogForLoading((Activity) mContext,"加载中...",false,false);
         getGril(size,paget).subscribe(new RxSubscriber<List<PhotoGirl>>(dialog) {
             @Override
             protected void _onNext(List<PhotoGirl> photoGirls) {
                mView.scouss(photoGirls);
                 LogUtils.logi("成功");
             }

             @Override
             protected void _onError(String message) {
                 LogUtils.logi(message);
             }
         });
    }

    private Observable<List<PhotoGirl>>   getGril(int size, int page){
        return RetrofitHelpers.getInstance(HostType.GANK_GIRL_PHOTO,false)
                .getPhotoList(size,page)
                .map(girlData -> girlData.getResults()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    }
}
